package com.news.view;

import java.util.List;
import java.util.Map;

import com.xiang.news.R;
import com.news.db.info.ContentInfo;
import com.rss.data.RssItem;

import android.R.color;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

public class TittleListAdapter extends BaseAdapter{
	private LayoutInflater mInflator;
	private List<Map<String, Object>> tittle_List;
	
	public TittleListAdapter(Context context, List<Map<String, Object>> list) {
		this.mInflator = LayoutInflater.from(context);
		this.tittle_List = list;
	}
	
	public int getCount() {
		System.out.println("mList.size()=" + tittle_List.size());
		return tittle_List.size();
	}
	
	public void resetData(List<Map<String, Object>> list) {
		this.tittle_List = list;
	}

	public Object getItem(int position) {
		return null;
	}

	public long getItemId(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewRss vRss = null;
		final int row = position;
		if(convertView == null) {
			vRss = new ViewRss();
			convertView = mInflator.inflate(R.layout.news_tittle_list_items, null);
			
			vRss.title = (TextView)convertView.findViewById(R.id.tittle_list_item_tittle);
			vRss.pubdate = (TextView)convertView.findViewById(R.id.tittle_list_item_pubdata);				
//			vRss.summary = (TextView)convertView.findViewById(R.id.tittle_list_item_summary);
			
			convertView.setTag(vRss);
		} else {
			vRss = (ViewRss)convertView.getTag();
		}
		String pubDate =  (String) tittle_List.get(position).get(RssItem.PUBDATE); 
		String title = (String)tittle_List.get(position).get(RssItem.TITLE);
		String summary = (String) tittle_List.get(position).get(RssItem.SUMMARY);
		String isRead = (String) tittle_List.get(position).get(ContentInfo.CONTENTREAD);
		
		System.out.println("tittle :"+title);
		vRss.title.setText(title);
		vRss.pubdate.setText(pubDate);		
//		vRss.summary.setText(summary);	
		
		if(isRead!=null){
			if(isRead.equals("1")){
				vRss.title.setTextColor(android.graphics.Color.GRAY);
				vRss.pubdate.setTextColor(android.graphics.Color.GRAY)	;
//				vRss.summary.setTextColor(android.graphics.Color.GRAY);
			}
		}
		
		return convertView;
	}
	
}

  final class ViewRss {
	public TextView title;
	public TextView pubdate;
//	public TextView summary;
}

